//
//  MYGCaseFilesDetailCell.swift
//  MYGrow
//
//  Created by 小火科技 on 2024/4/10.
//

import UIKit

class MYGCaseFilesDetailCell: UITableViewCell {

    var model:MYGCaseSubModel?{
        didSet {
            
            guard let data = model else {return}
            
            hospitalLabel.text = data.hospital
            infoLabel.text = "诊断: \(data.outpatient.info ?? "")"
            doctorLabel.text = "关联医生: \(data.outpatient.doctor ?? "")"
            let str = data.visit_time
            let start = str.index(str.startIndex, offsetBy: 8) // 获取起始索引
            let end = str.index(str.startIndex, offsetBy: 10) // 获取结束索引
            let range = start..<end // 创建索引范围
            let substr = str[range]
            titleLabel.text = String(substr)
        }
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        initUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func initUI(){
        contentView.backgroundColor = .white
        
        contentView.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.top.equalToSuperview()
            make.left.equalTo(29.5)
            make.height.width.equalTo(22)
        }
        
        contentView.addSubview(line)
        line.snp.makeConstraints { make in
            make.centerX.equalTo(titleLabel)
            make.top.equalTo(titleLabel.snp.bottom)
            make.bottom.equalToSuperview()
            make.width.equalTo(1)
        }
        
        contentView.addSubview(bgView)
        bgView.snp.makeConstraints { make in
            make.left.equalTo(titleLabel.snp.right).offset(17)
            make.top.equalToSuperview()
            make.right.equalToSuperview().offset(-15)
            make.height.equalTo(88)
        }
        
        bgView.addSubview(hospitalLabel)
        hospitalLabel.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(15)
            make.top.equalToSuperview().offset(9)
            make.right.equalToSuperview()
            make.height.equalTo(22)
        }
        
        bgView.addSubview(infoLabel)
        infoLabel.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(15)
            make.top.equalTo(hospitalLabel.snp.bottom).offset(5)
            make.right.equalToSuperview()
            make.height.equalTo(18)
        }
        
        bgView.addSubview(doctorLabel)
        doctorLabel.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(15)
            make.top.equalTo(infoLabel.snp.bottom).offset(5)
            make.height.equalTo(18)
        }
        
        
    }

    private lazy var titleLabel:UILabel = {
       let cont = UILabel()
        cont.font = .medium(12)
        cont.textAlignment = .center
        cont.textColor = .rgba(255, 255, 255, 1)
        cont.text = "18"
        cont.backgroundColor = .rgba(143, 134, 255, 1)
        cont.layer.cornerRadius = 11
        cont.layer.masksToBounds = true
        return cont
    }()
    
    private lazy var line:UIView = {
        let line = UIView()
        line.backgroundColor = .rgba(238, 238, 238, 1)
        return line
    }()
    
    var bgView:UIView = {
       let cont = UIView()
        cont.backgroundColor = .white
        cont.layerCornerRadius = SCALEWIDTH(6)
        cont.layer.shadowColor = RGBA(r: 0, g: 0, b: 0, a: 0.1).cgColor
        cont.layer.shadowOffset = CGSize(width: 0, height: 1)
        cont.layer.shadowRadius = 13
        cont.layer.shadowOpacity = 1
        cont.layer.masksToBounds = false
        return cont
    }()
    private lazy var hospitalLabel:UILabel = {
       let cont = UILabel()
        cont.font = .regular(16)
        cont.textColor = .rgba(43, 44, 44, 1)
        cont.text = "北京安贞医院"
        return cont
    }()
    private lazy var infoLabel:UILabel = {
       let cont = UILabel()
        cont.font = .regular(13)
        cont.textColor = .rgba(255, 0, 0, 1)
        cont.text = "诊断：病毒性心肌炎"
        return cont
    }()
    private lazy var doctorLabel:UILabel = {
       let cont = UILabel()
        cont.font = .regular(13)
        cont.textColor = .rgba(186, 186, 186, 1)
        cont.text = "关联医生：张医生"
        return cont
    }()
    
}
